# coding: utf-8
# @Author: 莫小鱼
from AutoApiTest.configs.setting import FILE_PATH
import configparser

from AutoApiTest.unit_tools.log_util import logs


class ConfigParse:
    """
    解析.ini后缀的配置文件
    """

    def __init__(self, file_path=FILE_PATH['ini']):
        self.file_path = file_path
        print(file_path)
        self.config = configparser.ConfigParser()
        self.read_config()

    def read_config(self):
        self.config.read(self.file_path)

    def get_value(self, section, option):
        """
        获取配置文件的值
        :param section: 头参
        :param option: key值
        :return:
        """
        try:
            return self.config.get(section, option)
        except Exception as e:
            logs.error(f"解析配置文件异常：{e}")

    def get_host(self,option):
        """
        专门获取接口的服务器ip地址
        :param option:
        :return:
        """
        return self.get_value('HOST',option)

    def get_mysql_conf(self,option):
        """
        获取mysql数据库信息
        :return:
        """
        return self.get_value('MYSQL',option)


if __name__ == '__main__':
    conf = ConfigParse()
    res = conf.get_mysql_conf('host')
    print(res)
